//
//  LGAuthenticateViewController.m
//  LuxuryGoods
//
//  Created by 纳里健康 on 2018/6/8.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGAuthenticateViewController.h"
#import "LGAuthenticateViewController+LGCollection.h"
#import "LGFooterView.h"

@interface LGAuthenticateViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray *_tableDataArray;
    
    NSIndexPath *_selectIndex;
    
    UIView *_tagView;
    
    NSMutableArray *_allDataArray;
    
    LGFooterView *_footerView;
    
   
}

@end

@implementation LGAuthenticateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"鉴定";
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self makeTabelData];
    
    [self makeTableView];
    
    [self makeCollectionView];
    
    [self makeFooterView];
}

- (void)makeTagView
{
    _tagView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 50)];
    _tagView.backgroundColor = UIColorFromRGB(0xAD9B6A);
    UITableViewCell *cell = [_tableView cellForRowAtIndexPath:_selectIndex];
    [cell.contentView addSubview:_tagView];
}

- (void)makeTabelData
{
    _tableDataArray = @[@"钱包",@"双肩包",@"单肩包",@"手提包",@"分类名称"];
    
    _selectIndex = [NSIndexPath indexPathForRow:0 inSection:0];
    
    NSDictionary *dict1 = @{@"tag":@"钱包",@"type":@"1",@"dataArray":@[],@"selectDataArray":@[]};
    NSDictionary *dict2 = @{@"tag":@"钱包",@"type":@"1",@"dataArray":@[],@"selectDataArray":@[]};
    NSDictionary *dict3 = @{@"tag":@"钱包",@"type":@"1",@"dataArray":@[],@"selectDataArray":@[]};
    NSDictionary *dict4 = @{@"tag":@"钱包",@"type":@"1",@"dataArray":@[],@"selectDataArray":@[]};
    NSDictionary *dict5 = @{@"tag":@"钱包",@"type":@"1",@"dataArray":@[],@"selectDataArray":@[]};
    
    _allDataArray = @[dict1,dict2,dict3,dict4,dict5].mutableCopy;
}

- (void)makeFooterView
{    
    _footerView = [[NSBundle mainBundle] loadNibNamed:@"LGFooterView" owner:self options:nil][0];
    
    [self.view addSubview:_footerView];
    
}



- (void)makeTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 120, 50 * _tableDataArray.count) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
}

#pragma mark -- tableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _tableDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"tableViewCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    cell.textLabel.text = _tableDataArray[indexPath.row];
    
    cell.textLabel.textColor = UIColorFromRGB(0x333333);
    
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    
    cell.backgroundColor = WHITE_COLOR;
    
    if(_selectIndex == indexPath)
    {
        cell.backgroundColor = UIColorFromRGB(0xF6F6F6);
        cell.textLabel.textColor = UIColorFromRGB(0xAD9B6A);
        _tagView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 50)];
        _tagView.backgroundColor = UIColorFromRGB(0xAD9B6A);
        [cell.contentView addSubview:_tagView];
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView animateWithDuration:0.2 animations:^{
        
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self->_selectIndex];
        
        cell.backgroundColor = WHITE_COLOR;
        cell.textLabel.textColor = UIColorFromRGB(0x333333);
        
        self->_selectIndex = indexPath;
        
        UITableViewCell *nextCell = [self.tableView cellForRowAtIndexPath:self->_selectIndex];
        
        CGRect currentCellRect = [self.tableView rectForRowAtIndexPath:self->_selectIndex];
        
        nextCell.backgroundColor = UIColorFromRGB(0xF6F6F6);
        nextCell.textLabel.textColor = UIColorFromRGB(0xAD9B6A);
        
        self->_tagView.y = currentCellRect.origin.y;
    }];
    
    
    [self showSelectTagInCollection];
}

//替换collectionView数据源
- (void)showSelectTagInCollection
{
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
